package test.print;

import javax.print.*;
import javax.print.attribute.*;
import java.io.*;

public class Printing {
	public static void main(String args[]) throws Exception {
		String filename = args[0];
		PrintRequestAttributeSet pras = 
			new HashPrintRequestAttributeSet();
		DocFlavor flavor = DocFlavor.INPUT_STREAM.PNG;
		PrintService printService[] = 
			PrintServiceLookup.lookupPrintServices(flavor, pras);
		PrintService defaultService = 
			PrintServiceLookup.lookupDefaultPrintService();
		PrintService service = ServiceUI.printDialog(null, 200, 200,
				printService, defaultService, flavor, pras);
		if (service != null) {
			DocPrintJob job = service.createPrintJob();
			FileInputStream fis = new FileInputStream(filename);
			DocAttributeSet das = new HashDocAttributeSet();
			Doc doc = new SimpleDoc(fis, flavor, das);
			job.print(doc, pras);
			Thread.sleep(10000);
		}
		System.exit(0);
	}
}
